//== SAGITTARIUS ============================================================================

//== BEGINNING OF CODE ===============================================================

#include "sagittarius/core/SagittariusCore.h"

//SAGITTARIUS headers:
#include "sagittarius/parallel/thread.h"
#include <errno.h>

#if SAGITTARIUS_IS_POSIX_VAR
    //OS thread funcs:
    long  sg_clone(void (*thread_func)(void*), void* param);

    //Wrapper funcs:
    int spawn_successful(spawnresult r) {
        if(r < 0 || errno)
            return 0;
        else
            return 1;
    }

    spawnresult sg_spawn(void (*thread_func)(void*), void* param) {
        return sg_clone(thread_func, param);
    }
#elif SAGITTARIUS_PLATFORM == SAGITTARIUS_PLATFORM_WIN
    //Wrapper funcs:
    int spawn_successful(spawnresult r) {
        if(r == NULL)
            return 0;
        else
            return 1;
    }

    spawnresult sg_spawn(void (*thread_func)(void*), void* param) {
        return CreateThread(
            NULL,        //security
            0,           //stack size <- default
            thread_func, //address of fun
            NULL,        //no argument
            0,           //flags
            NULL         //can be an addr at which to output thread ID
            );
    }
#else
#   error "Threading not supported on this platform"
#endif